#include <iostream>

using namespace std;

int main(){
	//varibale declaration
	int sopt;
	int mang[100];
	int i,j,tmp;
	//processing
	cout <<"Nhap so phan tu trong mang: ";
	cin >> sopt;
	for(i = 0;i < sopt; ++i)
	{
		cout<< "Gia tri phan tu thu "<<i+1<<" : ";
		cin >> mang[i];
	}

	//arrange  -->
	for(i = 0; i < sopt -1;++i)
	{
		for(j = i + 1;j < sopt;++j)
		{
			if(mang[i] > mang[j])
			{
				tmp = mang[i];
				mang[i] = mang[j];
				mang[j] = tmp;
			}
		}
	}
	//nhap key can tim
	int key;
	cout << "Nhap tu khoa can tim: ";
	cin >> key;
	//search
	int mid,first = 0,last = sopt - 1;
	do
	{
		mid = (first + last) / 2;
		if (mang[mid] > key) last = mid - 1;
		else first = mid + 1;
	}while((mang[mid] != key) && (first < last));

	if(mang[mid] = key) cout << key <<" co trong danh sach!" << endl;
	else cout << key << " khong co trong danh sach!" << endl;
	return 0;
}